﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Gift.Model;
using Gift.WebApp;

namespace WebApp.admin.basic
{
    public partial class freightTemplate : BaseAdmin
    {

    
        tbFreightTemplate oFreightTemplate;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BuilForm();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (! string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                oFreightTemplate = BaseFactory.theFreightTemplate.GetModel(int.Parse(Request.QueryString["id"]));

                    oFreightTemplate.freightTemplateName =  this.txtFreightTemplateName.Value.Trim();
                    oFreightTemplate.freightThat = this.txtaFreightThat.Value.Trim();
                    if (BaseFactory.theFreightTemplate.Update(oFreightTemplate))
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");window.location.href='freightTemplateList.aspx';</script>");
                    }
                    else
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
                    }
                   
            
            }
            else
            {
                oFreightTemplate = new tbFreightTemplate();
                oFreightTemplate.freightTemplateName = this.txtFreightTemplateName.Value.Trim();
                oFreightTemplate.freightThat = this.txtaFreightThat.Value.Trim();
                oFreightTemplate.createTime = DateTime.Now;
                oFreightTemplate.CompanyId = int.Parse(base.Administrator.CompanyId);
                if (BaseFactory.theFreightTemplate.Add(oFreightTemplate) > 0)
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加成功！\");window.location.href='freightTemplateList.aspx';</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加失败！\");</script>");
                }
            }

        }

        void BuilForm()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                oFreightTemplate = BaseFactory.theFreightTemplate.GetModel(int.Parse(Request.QueryString["id"]));
                if (oFreightTemplate != null)
                {
                    this.txtFreightTemplateName.Value = oFreightTemplate.freightTemplateName;
                    this.txtaFreightThat.Value = oFreightTemplate.freightThat;
 
                }
            }
        }
    }
}